package mongo.controller;

import mongo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mongo")
public class CrudController {
    @Autowired
    private MongoTemplate mongoTemplate;

    @GetMapping("/save")
    public void save() {
        User user = new User("1001", "zhp", "123456");
        mongoTemplate.save(user);
    }

    @GetMapping("/search")
    public void search() {
        List<User> userList = mongoTemplate.findAll(User.class);
        System.out.println(userList);
    }
}
